import os
import time
import requests
from bs4 import BeautifulSoup

# prompt 和 关键词匹配
def get(url):
    x = requests.get(url)
    soup = BeautifulSoup(x.text, "html.parser")
    for item in soup.select(".cell > a > span"):
        print(item.text)
        txt = item.text
        txts.append(txt)

if __name__ == "__main__":
    txts = []
    for i in range(5):
        url = f"https://www.doutub.com/img_lists/miao/{i+1}"
        get(url)

    file_path = os.path.join('cache', time.strftime("%Y%m%d%H%M%S", time.localtime())+".txt")
    with open(file_path, 'w',encoding="utf8") as f: 
        for line in txts:
            f.write(line+os.linesep)
